package net.chenlin.dp.modules.business.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.chenlin.dp.common.entity.Page;
import net.chenlin.dp.common.entity.R;
import net.chenlin.dp.modules.business.entity.dto.LineChartQueryDto;
import net.chenlin.dp.modules.business.entity.vo.lineLossAnalysis.DeviceHistoryDataVo;
import net.chenlin.dp.modules.business.entity.vo.lineLossAnalysis.LineLossAnalysisListVo;
import net.chenlin.dp.modules.business.service.LineChartService;
import net.chenlin.dp.modules.sys.controller.AbstractController;
import net.chenlin.dp.modules.sys.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author Yangsm
 * @ClassName: LineChartController
 * @Description: TODO
 * @date 2022年11月02日 21:59
 */
@Slf4j
@RestController
@RequestMapping("/lineChart")
@Api(tags = "线损分析-折线图")
public class LineChartController extends AbstractController {

    @Autowired
    private LineChartService lineChartService;

    @RequestMapping(value = "/getLineChart", method = RequestMethod.POST)
    @ApiOperation(value = "获取折线图数据")
    public R getLineChart(@RequestBody LineChartQueryDto queryDto) {
        R r = lineChartService.getLineChart(queryDto);
        return r;
    }

    @RequestMapping(value = "/getLineChartQueryTime", method = RequestMethod.GET)
    @ApiOperation(value = "获取有数据的时间")
    public R getLineChartQueryTime(String testNo) {
        R r = lineChartService.getLineChartQueryTime(testNo);
        return r;
    }

    @RequestMapping(value = "/getLineLossAnalysisList", method = RequestMethod.POST)
    @ApiOperation(value = "线损分析列表")
    public Page<LineLossAnalysisListVo> getLineLossAnalysisList(@RequestBody Map<String, Object> params) {
        SysUserEntity user = getUser();
        if(null == user){
            log.info("未获取到当前登录用户！");
            return new Page<>();
        }
        if(user.getOrgId() != 1){
            params.put("orgId",user.getOrgId());
        }
        return lineChartService.getLineLossAnalysisList(params);
    }

    @RequestMapping(value = "/getDeviceHistoryData", method = RequestMethod.POST)
    @ApiOperation(value = "线损分析列表查看详情-查看历史数据")
    public Page<DeviceHistoryDataVo> getDeviceHistoryData(@RequestBody Map<String, Object> params) {
        return lineChartService.getDeviceHistoryData(params);
    }


    @RequestMapping(value = "/getNewLineChart", method = RequestMethod.POST)
    @ApiOperation(value = "获取折线图数据--最新接口")
    public R getNewLineChart(@RequestBody LineChartQueryDto queryDto) {
        R r = lineChartService.getNewLineChart(queryDto);
        return r;
    }


}
